/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.xeerkat.restlet.xmpp;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.infoset.xml.Element;
import org.infoset.xml.XMLException;
import org.infoset.xml.util.XMLWriter;
import org.restlet.data.MediaType;
import org.restlet.representation.OutputRepresentation;

/**
 *
 * @author alex
 */
public class StanzaRepresentation extends OutputRepresentation  {

   Element stanza;
   public StanzaRepresentation(Element stanza) {
      super(MediaType.APPLICATION_XML);
      this.stanza = stanza;
   }
   
   public Element getStanza() {
      return stanza;
   }
   
   public void release() {
      super.release();
      this.stanza = null;
   }
   
   public void write(OutputStream os) 
      throws IOException
   {
      try {
         Writer w = new OutputStreamWriter(os,"UTF-8");
         XMLWriter.writeElement(stanza, w);
         w.flush();
      } catch (XMLException ex) {
         throw new IOException(ex.getMessage(),ex.getCause());
      }
   }

}
